/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cambioHorario.java
 *
 * Created on 15-11-2011, 09:48:49 AM
 */
package androidutal;

import java.awt.BorderLayout;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

/**
 *
 * @author Roberto
 */
public class jPanelCambioHorario1 extends javax.swing.JPanel implements java.io.Serializable{
    private  JVentana ventana;
    private String[] profesores ;
    private  String[] cursos;
    private boolean isBorrador;

    /** Creates new form cambioHorario */
    public jPanelCambioHorario1(JVentana ventana)  {
        
         Datos datos;      
        try {
            datos = new Datos();
             this.profesores= datos.getProfe();
             this.cursos= datos.getCurso();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(jPanelCambioHorario1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(jPanelCambioHorario1.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        this.ventana = ventana;
        this.isBorrador = false;
    }
    public boolean isBorrador() {
        return isBorrador;
    }
    public void setIsBorrador(boolean isBorrador) {
        this.isBorrador = isBorrador;
    }
    public JComboBox getjCursos() {
        return jCursos;
    }

    public void setjCursos(JComboBox jCursos) {
        this.jCursos = jCursos;
    }

    public JTextArea getjObservaciones() {
        return jObservaciones;
    }

    public void setjObservaciones(JTextArea jObservaciones) {
        this.jObservaciones = jObservaciones;
    }

    public JTextArea getjPlainificacionFinal() {
        return jPlainificacionFinal;
    }

    public void setjPlainificacionFinal(JTextArea jPlainificacionFinal) {
        this.jPlainificacionFinal = jPlainificacionFinal;
    }

    public JTextArea getjPlanificacionOriginal() {
        return jPlanificacionOriginal;
    }

    public void setjPlanificacionOriginal(JTextArea jPlanificacionOriginal) {
        this.jPlanificacionOriginal = jPlanificacionOriginal;
    }

    public JComboBox getjProfesores() {
        return jProfesores;
    }

    public void setjProfesores(JComboBox jProfesores) {
        this.jProfesores = jProfesores;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jProfesores = new javax.swing.JComboBox(this.profesores);
        jLabel3 = new javax.swing.JLabel();
        jCursos = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jPublicar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPlanificacionOriginal = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPlainificacionFinal = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jObservaciones = new javax.swing.JTextArea();

        jLabel2.setText("jLabel2");

        setBackground(new java.awt.Color(0, 0, 0));
        setMaximumSize(new java.awt.Dimension(31, 23));
        setMinimumSize(new java.awt.Dimension(400, 377));
        setPreferredSize(new java.awt.Dimension(400, 377));

        jLabel1.setForeground(new java.awt.Color(240, 240, 240));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Cambio horario");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        jProfesores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jProfesoresActionPerformed(evt);
            }
        });

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Curso: ");

        jCursos.setModel(new javax.swing.DefaultComboBoxModel(this.cursos));
        jCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCursosActionPerformed(evt);
            }
        });

        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Profesor:");

        jPanel3.setBackground(java.awt.Color.black);

        jButton3.setBackground(java.awt.Color.white);
        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPublicar.setBackground(java.awt.Color.white);
        jPublicar.setText("Publicar");
        jPublicar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPublicarActionPerformed(evt);
            }
        });

        jButton2.setBackground(java.awt.Color.white);
        jButton2.setText("Borrador");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
                .addComponent(jPublicar)
                .addGap(28, 28, 28)
                .addComponent(jButton3))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPublicar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        jLabel5.setForeground(java.awt.Color.white);
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel5.setText("Planificacion original:");

        jLabel6.setForeground(java.awt.Color.white);
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel6.setText("Planificacion final:");

        jPlanificacionOriginal.setColumns(20);
        jPlanificacionOriginal.setLineWrap(true);
        jPlanificacionOriginal.setRows(5);
        jPlanificacionOriginal.setWrapStyleWord(true);
        jScrollPane1.setViewportView(jPlanificacionOriginal);

        jPlainificacionFinal.setColumns(20);
        jPlainificacionFinal.setLineWrap(true);
        jPlainificacionFinal.setRows(5);
        jPlainificacionFinal.setWrapStyleWord(true);
        jScrollPane2.setViewportView(jPlainificacionFinal);

        jLabel7.setForeground(java.awt.Color.white);
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel7.setText("Observaciones:");

        jObservaciones.setColumns(20);
        jObservaciones.setLineWrap(true);
        jObservaciones.setRows(5);
        jObservaciones.setWrapStyleWord(true);
        jScrollPane3.setViewportView(jObservaciones);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel4)
                                        .addComponent(jLabel3))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(1, 1, 1)
                                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE))
                                        .addComponent(jCursos, javax.swing.GroupLayout.Alignment.LEADING, 0, 309, Short.MAX_VALUE)
                                        .addComponent(jProfesores, javax.swing.GroupLayout.Alignment.LEADING, 0, 309, Short.MAX_VALUE)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(1, 1, 1)
                                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                                            .addGap(1, 1, 1)))))
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jProfesores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jCursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jProfesoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProfesoresActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jProfesoresActionPerformed

private void jCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCursosActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jCursosActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    if(this.isBorrador()){
        this.jButton2ActionPerformed(evt);
        this.ventana.getResumen().eliminarFila();
            this.setVisible(false);
            ventana.add(ventana.getResumen(),BorderLayout.CENTER);
            ventana.getResumen().setVisible(true);
    }
    else{
            this.setVisible(false);
            ventana.add(ventana.getResumen(),BorderLayout.CENTER);
            ventana.getResumen().setVisible(true);
    }
    this.desbloquear();
}//GEN-LAST:event_jButton3ActionPerformed

private void jPublicarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPublicarActionPerformed
// TODO add your handling code here:
     if(!jPlanificacionOriginal.getText().equals("")&& !jPlainificacionFinal.getText().equals("")&&!jObservaciones.getText().equals("")){
         if(this.isBorrador)
               this.ventana.getResumen().eliminarFila();
        ventana.getBaseDeDatos().addHorario((String)jProfesores.getSelectedItem(),
       (String)jCursos.getSelectedItem( ),
        this.jPlanificacionOriginal.getText(),this.jPlainificacionFinal.getText(),
        this.jObservaciones.getText(),false);
        Date date=new Date();
        ventana.getResumen().insertarInfo((String)this.jCursos.getSelectedItem(),date.toString(),"No" );
        this.setVisible(false);
        ventana.add(ventana.getResumen(),BorderLayout.CENTER);
        ventana.getResumen().setVisible(true);
        ventana.save();
        ventana.saveToWS();
    }
    else{
        JOptionPane.showMessageDialog(this, "Rellene todos los campos obligatorios");
    } 
}//GEN-LAST:event_jPublicarActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    
        ventana.getBaseDeDatos().addHorario((String)jProfesores.getSelectedItem(),
       (String)jCursos.getSelectedItem( ),
        this.jPlanificacionOriginal.getText(),this.jPlainificacionFinal.getText(),
        this.jObservaciones.getText(),true);
        Date date=new Date();
        ventana.getResumen().insertarInfo((String)this.jCursos.getSelectedItem(),date.toString(),"Si");
        this.setVisible(false);
        ventana.add(ventana.getResumen(),BorderLayout.CENTER);
        ventana.getResumen().setVisible(true);
        ventana.save();
}//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jCursos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTextArea jObservaciones;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextArea jPlainificacionFinal;
    private javax.swing.JTextArea jPlanificacionOriginal;
    private javax.swing.JComboBox jProfesores;
    private javax.swing.JButton jPublicar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    // End of variables declaration//GEN-END:variables

    public void bloquear(){
        this.getjCursos().setEnabled(false);
        this.getjObservaciones().setEditable(false);
        this.getjPlanificacionOriginal().setEditable(false);
        this.getjPlainificacionFinal().setEditable(false);
        this.getjProfesores().setEnabled(false);
        this.jButton2.setVisible(false);
        this.jPublicar.setVisible(false);
    }
    public void desbloquear(){
        this.getjCursos().setEnabled(true);
        this.getjObservaciones().setEditable(true);
        this.getjPlanificacionOriginal().setEditable(true);
        this.getjPlainificacionFinal().setEditable(true);
        this.getjProfesores().setEnabled(true);
        this.jButton2.setVisible(true);
        this.jPublicar.setVisible(true);
    }
}
